<template>
    <div class="order-report">
        <div class="report-table-top-title">应用宝</div>
        <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 80px; text-align: right"
                >
                    设备类型:
                </div>
                <div class="report-table-form1-item" style="width: 220px">
                    <el-select
                        class="items"
                        v-model="searchParam.terminalType"
                        filterable
                        placeholder="请选择"
                        size="small"
                    >
                        <el-option
                            v-for="(item, index) in terminalTypeList"
                            :key="index"
                            :label="item.terminalTypeName"
                            :value="item.terminalTypeValue"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 80px; text-align: right"
                >
                    是否上架:
                </div>
                <div class="report-table-form1-item" style="width: 220px">
                    <el-select
                        class="items"
                        v-model="searchParam.isOnShelf"
                        size="small"
                    >
                        <el-option label="全部" value=""></el-option>
                        <el-option label="是" value="1"></el-option>
                        <el-option label="否" value="0"></el-option>
                    </el-select>
                </div>
                <div class="report-table-form1-item">
                    <el-button type="primary" size="small" @click="reSearch"
                        >查询
                    </el-button>
                    <el-button
                        type="primary"
                        plain
                        size="small"
                        @click="initParams"
                        >重置</el-button
                    >
                    <el-button
                        type="primary"
                        size="small"
                        @click="$emit('add', {})"
                        >添加应用包</el-button
                    >
                </div>
            </div>
        </div>
        <div class="page-padding-gray-small"></div>
        <div class="report-table-wrapper">
            <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="tabData"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="appPackageID"
                    label="应用包序号"
                    min-width="90"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageName"
                    label="应用包名称"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="introducePicUrl"
                    label="应用包介绍图片地址"
                    min-width="160"
                    show-overflow-tooltip
                >
                <template slot-scope="scope">
                    <el-image
                    style="width: 100px; height: 80px"
                    :src="scope.row.introducePicUrl">
                    </el-image>
                </template>
                
                </el-table-column>
                <el-table-column
                    prop="introduceText"
                    label="应用包简介文本"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
               
                <el-table-column
                    prop="md5"
                    label="md5"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="appPackageType"
                    label="应用包类型"
                    min-width="160"
                    show-overflow-tooltip
                >
                <template slot-scope="scope">
                    <span>{{ scope.row.appPackageTypeName }}</span>
                </template>
                </el-table-column>
                <el-table-column
                    prop="auther"
                    label="应用包作者"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageUrl"
                    label="应用包下载地址"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageVersionCode"
                    label="应用包版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="internalPackageVersionCode"
                    label="应用包内部版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="isOnShelf"
                    label="是否上架"
                    min-width="160"
                    show-overflow-tooltip
                >
                 <template slot-scope="scope">
                        {{ scope.row.isOnShelf === 1 ? '是' : '否' }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="remarks"
                    label="备注"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="createTime"
                    label="创建时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="upgradeTime"
                    label="更新时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column fixed="right" label="操作" width="200px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="small" @click="$emit('add', scope.row)"
                        >编辑
                         </el-button>
                        <el-button type="primary" size="small" @click="updateUpgradeStatus(scope.row)"
                        ><span v-if="scope.row.isOnShelf == 0">上架</span><span v-else>下架</span>
                         </el-button>
                    </template>                    
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页 -->
        <div class="report-table-block">
            <div class="report-table-block-in">
                <el-pagination
                    background
                    :current-page.sync="currentPage"
                    @current-change="handleCurrentChange"
                    :page-size="pageSize"
                    layout="prev, pager, next, total"
                    :total="totalNum"
                ></el-pagination>
            </div>
        </div>
        <showMS
            :value.sync="isShowMS"
            :msName="msName"
            :currRow="currRow"
        ></showMS>
    </div>
</template>

<script type="text/ecmascript-6">
import showMS from './components/showMS'
import addPlace from './components/addPlace'
export default {
    components: {
        showMS,
        addPlace
    },
    data: function () {
        return {
            currRow: {},
            msName: '',
            isShowMS: false,
            terminalTypeList: [], // 设备类型
            statusList: [], // 状态列表
            row: null,
            loading: false,
            searchParam: {
                terminalType: '',
                isOnShelf: ''
            },
            agentList: [],
            currentPage: 1,
            pageSize: 10,
            totalNum: 0,
            tabData: []
        }
    },
    mounted () {
    },
    created () {
        this.getOnlyTerminalTypeV2()
        this.getList()
    },
    watch: {
    },
    props: {
        underLine: null
    },
    methods: {
        showMS (name, row) {
            this.isShowMS = true
            this.msName = name
            this.currRow = row
        },
        initParams () {
            this.searchParam.isOnShelf = ''
            this.searchParam.terminalType = ''
            this.currentPage = 1
            this.pageSize = 10
            this.getList()
        },
        updateUpgradeStatus (row) {
            this.$confirm('确定执行此操作吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.post(this.$store.state.IP + '/appStore/packageIsOnShelfSwitch', {
                    appPackageID: row.appPackageID,
                    isOnShelf: row.isOnShelf === 1 ? 0 : 1
                },
                    {
                        'emulateJSON': false
                    }
                ).then(response => {
                    console.log('-------------------------------------------')
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                })
            }).catch(() => {
            })
        },
        getOnlyTerminalTypeV2 () {
            this.$http.get(this.$store.state.IP + '/system/company/getOnlyTerminalTypeV2?isAll=1',
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.terminalTypeList = response.res
                }
            }, response => {
            })
        },
        delRow (row) {
            console.log(row)
            this.$confirm('确定删除吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    params: {
                    }
                }
                this.$http.get(this.$store.state.IP + '/upgradeManage/deleteUpgrade?upgradePackageID=' + row.upgradePackageID, params).then(response => {
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                    console.log('调用添加失败')
                })
            }).catch(() => {
            })
        },
        handleCurrentChange (page) {
            // 换页
            this.currentPage = page
            this.getList()
        },
        reSearch () {
            this.currentPage = 1
            this.getList()
        },
        getList () {
            // 获取 所有 应用包列表
            this.$http.post(this.$store.state.IP + '/appStore/appPackagePage', {
                page: this.currentPage - 1,
                size: this.pageSize,
                terminalType: this.searchParam.terminalType,
                isOnShelf: this.searchParam.isOnShelf
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                this.tabData = []
                if (response.ret === '0') {
                    this.tabData = response.res.list
                    this.totalNum = response.res.total
                }
                if (response.ret !== '0') {
                    console.log('调用获取所有代理商失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.el-dropdown-link
    color: #409EFF
    cursor: pointer

.order-report
    width: 100%
    background: #fff
    min-height: calc(100vh - 65px)
    position: relative

    .report-table-top-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background: #f1f0f5

    .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing: border-box
        background: #fff
        overflow: hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align: left

                &.big
                    margin-right: 100px

    .report-table-block
        width: 100%
        padding-top: 22px
        height: 50px
        background: #fff
        box-sizing: border-box

        .report-table-block-in
            float: right
            padding-right: 17px

    .page-padding-gray-small
        width: 100%
        height: 22px
        background: #f1f0f5

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .report-table-total
        width: 100%
        font-size: 16px
        color: #409EFF
        padding: 22px
        margin-top: 22px
        box-sizing: border-box
        background: #fff

    .page-all-loading
        position: fixed
        top: 55%
        left: 40%
        width: 200px

.title
    display: inline-block
    min-width: 120px
    text-align: right
    font-weight: bold
    line-height: 35px

.value
    display: inline-block
    line-height: 35px
    min-width: 150px

.items
    width: 200px

.item
    margin-bottom: 0px
</style>

